﻿@*参数列表：1.用于保存选择的用户ID的控件ID，2.用于保存选择的用户名称的控件ID 
用法：@Html.Partial("_OrgUserPartial", new List<object> {  "ShareUsers", "ShareUsersName" })*@
@model List<object>
<script>
    //获取用户列表
    function GetUserListMulti(queryData) {
        $('#userdlg1').dialog('open').dialog('setTitle', '选择用户');
        $('#userlist1').datagrid({
            title: '用户列表',
            idField: 'UserID',
            fitColumns: 'true',
            singleSelect: false,//是否单选
            autoRowHeight: true,
            nowrap: true,
            striped: true,
            pagination: true,
            url: 'User/GetList',
            queryParams: queryData,    //参数为了多条件查询预留
            columns: [[
                { field: 'ck', checkbox: true },
                { field: 'UserID', title: 'ID', hidden: true },
                { field: 'UserName', title: '账号', width: 180 },
                { field: 'EmployeeName', title: '姓名', width: 180 },
                { field: 'DepartmentID', title: '部门', width: 180 },
                { field: 'RoleID', title: '角色（职务）', width: 180 },
                { field: 'Telephone', title: '固定电话', width: 180 }
            ]],
        });
    }

    //选择部门主管
    function SelectUserMulti() {
        var rows = $("#userlist1").datagrid("getSelections");
        if (rows.length >= 1) {
            var userID = "";
            var employeeName = "";
            for (var i = 0; i < rows.length; i++) {
                if (userID == "")
                    userID = rows[i].UserID;
                else
                    userID = userID + ";" + rows[i].UserID;
                if (employeeName == "")
                    employeeName = rows[i].EmployeeName
                else
                    employeeName = employeeName + ";" + rows[i].EmployeeName;
                $("#@Model[0].ToString()").val(userID);//保存选择的用户ID
                $("#@Model[1].ToString()").val(employeeName);//保存选择的用户名称
                $('#userdlg1').dialog('close');
            }
        }
        else {
            $.messager.alert("友情提示", "请选择用户");
        }
    }

    //根据部门ID，用户名查询用户
    function SearchMulti() {
        var depatmentID = $('#comb_Search_DepartmentParentID').combotree('getValue');
        var username = $('#userName').val();

        if (depatmentID == '请选择部门') {
            depatmentID = '';
        }
        if (username == '用户名称') {
            username = '';
        }

        var querData = {
            j_depatmentID: depatmentID,
            j_username: username
        };

        GetUserListMulti(querData);
    }
</script>
<div id="userdlg1" class="easyui-dialog" style="width: 480px; height: 380px; padding: 10px 10px"
    closed="true" buttons="#userdlg-buttons1" modal="true" resizable="true">

    <table id="userlist1" class="easyui-datagrid" width="100%" toolbar="#usertoolbar1">
    </table>
    <div id="usertoolbar1">
        <table>
            <tr>
                <td>
                    <input class="easyui-validatebox" type="text" id="userName" name="userName"
                        value="用户名称" onfocus="if(value==defaultValue){value='';this.style.color='#000'}" onblur="if(!value){value=defaultValue;this.style.color='#999'}" style="color: #999999" />
                </td>
                <td>
                    <input value="请选择部门"
                        id="comb_Search_DepartmentParentID" class="easyui-combotree"
                        data-options="url:'/Department/GetTreeList',required:true,
                        onSelect: function(rec){  
                            $('#DepartmentParentID').val(rec.id); }" />
                </td>
                <td>
                    <a href="#" class="easyui-linkbutton" iconcls="icon-search" onclick="SearchMulti()">查询</a>
                </td>
            </tr>
        </table>


    </div>

    <div id="userdlg-buttons1">
        <a href="#" class="easyui-linkbutton" iconcls="icon-ok" onclick="SelectUserMulti()">确定</a>
        <a href="#" class="easyui-linkbutton" iconcls="icon-cancel" onclick="javascript:$('#userdlg1').dialog('close')">取消</a>
    </div>
</div>
